<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>
	<body>
		<button onclick="fun1()">添加文本</button>
		<button onclick="fun2()">添加图片</button>
		<button onclick="fun3()">删除第一个文本</button>
		<button onclick="fun4()">删除最后一个图片</button>
		<div id="con"></div>
		<script type="text/javascript">
			var i = 1;
			function fun1(){
				var temp = document.createElement("div");
				temp.innerHTML="文字"+(i++);
				temp.setAttribute("style","color: red;")
				document.getElementById("con").appendChild(temp);
			}
			function fun2(){
				var temp = document.createElement("img");
				temp.setAttribute("src","img/off.png");
				temp.setAttribute("width","100px");	
				document.getElementById("con").appendChild(temp);
			}
			function fun3(){
				var temp = document.querySelector("#con>div");
				temp.parentNode.removeChild(temp);
			}
			function fun4(){
				var imgs = document.querySelectorAll("#con>img");
				var temp = imgs[imgs.length-1];
				temp.parentNode.removeChild(temp);
			}
		</script>
	</body>
</html>
